package com.boot4g.admin.module.publish.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.boot4g.admin.module.publish.service.PublishService;
import com.boot4g.entity.PublishEntity;
import com.boot4g.utils.PageUtils;
import com.boot4g.utils.Query;
import com.boot4g.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * 
 * 
 * @author chenjinjie
 * @email guangyaoliangzijie@163.com
 * @date 2018-03-07 14:27:41
 */
@RestController
@RequestMapping("sys/publish")
public class PublishController {
	@Autowired
	private PublishService publishService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

        Page<PublishEntity> page = publishService.selectByPage(query.getPagination(),query);

        PageUtils pageUtil = new PageUtils(page.getRecords(), page.getTotal(), query.getLimit(), query.getCurrPage());

		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{rid}")
//	@RequiresPermissions("publish:info")
	public R info(@PathVariable("rid") Long rid){
		PublishEntity publish = publishService.selectById(rid);
		
		return R.ok().put("publish", publish);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
//	@RequiresPermissions("publish:save")
	public R save(@RequestBody PublishEntity publish){
		publish.setCreateTm(new Date());
		publishService.insert(publish);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
//	@RequiresPermissions("publish:update")
	public R update(@RequestBody PublishEntity publish){
		publish.setUpdateTm(new Date());
		publishService.updateById(publish);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
//	@RequiresPermissions("publish:delete")
	public R delete(@RequestBody Long[] rids){
		publishService.deleteBatchIds(Arrays.asList(rids));
		
		return R.ok();
	}
	
}
